﻿using System.Collections.ObjectModel;

namespace Rio.Framework.Pages.Workflow.Models
{
    public class DataItemTreeViewCollection : ObservableCollection<DataItemTreeView>
    {
        #region Fields

        private DataItemTreeView _root;

        #endregion Fields

        #region Constructors

        public DataItemTreeViewCollection(DataItemTreeView P_owner)
        {
            this.Root = P_owner;
        }

        #endregion Constructors

        #region Properties

        private DataItemTreeView Root
        {
            get
            {
                return this._root;
            }
            set
            {
                this._root = value;
            }
        }

        #endregion Properties

        #region Methods

        protected override void ClearItems()
        {
            foreach (DataItemTreeView item in this)
            {
                item.Parent = null;
            }
            base.ClearItems();
        }

        protected override void InsertItem(int P_iIndex, DataItemTreeView P_item)
        {
            P_item.Parent = this.Root;

            base.InsertItem(P_iIndex, P_item);
        }

        protected override void RemoveItem(int P_iIndex)
        {
            this[P_iIndex].Parent = null;

            base.RemoveItem(P_iIndex);
        }

        protected override void SetItem(int P_iIndex, DataItemTreeView P_item)
        {
            P_item.Parent = this.Root;

            base.SetItem(P_iIndex, P_item);
        }

        #endregion Methods
    }
}